package com.companyName.sample.core.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Calendar;


/*@Component
@Configurable
@EnableScheduling*/
public class UserTasks {
    private final static Logger logger = LoggerFactory.getLogger(UserTasks.class);

    //每3分钟执行一次
    @Scheduled(fixedRate = 1000 * 180)
    public void runIqiyiTask() throws Exception {
        logger.info("runIqiyiTask start");
        //撰写业务代码
        Thread.sleep(10000);
        logger.info("runIqiyiTask end");
    }

    //每天凌晨1点
    @Scheduled(cron = "0 0 1 * * *")
    public void run3rdPart() throws Exception {
        Calendar ca = Calendar.getInstance();
        ca.add(Calendar.DATE, -1);

        logger.info("run3rdPart start");
        //撰写业务代码
        Thread.sleep(10000);
        logger.info("run3rdPart end");
    }
}
